/**
 * 
 */
package com.yy.tech.data.coder.secret.utils;

import com.yy.tech.data.context.SecretContent;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Base64;

public final class Base64Encryptor {

	public static String encrypt(final String str) {
		final byte[] bytes = str.getBytes(Charset.forName(SecretContent.DEFAULT_CHARSET));
		return Base64.getEncoder().encodeToString(bytes);
	}

	public static String decrypt(final String str) {
		final byte[] bytes = Base64.getDecoder().decode(str);
		try {
			return new String(bytes, SecretContent.DEFAULT_CHARSET);
		} catch (final UnsupportedEncodingException e) {
		}
		return str;
	}
}
